package com.disdr;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.aliyun.oss.ServiceException;
import org.apache.http.client.utils.DateUtils;
import org.roaringbitmap.RoaringBitmap;

import java.io.DataOutput;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Base64;
import java.util.Date;
import java.util.List;

public class 位图解析 {


    public static void main(String[] args) throws IOException {
        xxx();
    }

    public static void xxx() throws IOException {
        //解密
        ByteBuffer bbf = ByteBuffer.wrap(Base64.getDecoder().decode("OjAAAAEAAAAAAAEAEAAAAAQABQA="));
        RoaringBitmap rbm = new RoaringBitmap();
        rbm.deserialize(bbf);
        System.out.println(rbm);
        for (Integer s : rbm){
            System.out.println(s);
        }
        rbm.add(96818);
        rbm.add(96819);
        System.out.println(rbm.contains(3));
        System.out.println(rbm.contains(4));
        System.out.println(rbm.contains(96818));
        System.out.println(rbm.contains(6));
        //加密
        ByteBuffer aaa = ByteBuffer.wrap(new byte[rbm.serializedSizeInBytes()]);
        rbm.serialize(aaa);
        System.out.println(Base64.getEncoder().encodeToString(aaa.array()));
        for (Integer s : rbm){
            System.out.println(s);
        }
    }

    public static void yy(RoaringBitmap rr) throws IOException {
        ByteBuffer outbb = ByteBuffer.allocate(rr.serializedSizeInBytes());
        rr.serialize(new DataOutputStream(new OutputStream(){
            ByteBuffer mBB;
            OutputStream init(ByteBuffer mbb) {mBB=mbb; return this;}
            public void close() {}
            public void flush() {}
            public void write(int b) {
                mBB.put((byte) b);}
            public void write(byte[] b) {mBB.put(b);}
            public void write(byte[] b, int off, int l) {mBB.put(b,off,l);}
        }.init(outbb)));
//
        outbb.flip();
        String serializedstring = Base64.getEncoder().encodeToString(outbb.array());
    }
}
